package com.inspection.job;

import com.inspection.model.App;
import com.inspection.model.AppStatus;
import com.inspection.operator.XmlAnalysis;
import com.inspection.utils.AppConfig;
import net.sf.ehcache.Element;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.HashMap;

/**
 * Created by zhujun on 2015-6-5.
 *
 * APP监控过程中使用的HTTP请求
 *
 */
public class HttpRequestJob implements Job{


    /**
     * @param jobExecutionContext
     * @throws JobExecutionException
     */
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        App app = (App) jobDataMap.get("value");

        AppStatus appStatus = XmlAnalysis.getHttpInfo(app.getUrl());
        appStatus.setApp(app);

        HashMap cache_apps = null;
        if(AppConfig.cache.get("apps")==null){
            cache_apps = new HashMap();
        }else{
            cache_apps = (HashMap)AppConfig.cache.get("apps").getValue();
        }

        cache_apps.put(jobDataMap.get("key"), appStatus);
        Element element = new Element("apps",cache_apps);
        AppConfig.cache.put(element);


    }



}